package com.gx.common.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * @Author Liu-pj
 * @Date 2022/2/22 14:47
 * 分页工具类
 **/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "分页信息")
public class PageBean<T> {

    // 当前页
    @ApiModelProperty(value = "当前页")
    private Integer currentNo;
    // 单页显示数据条数
    @ApiModelProperty(value = "单页条数")
    private Integer pageSize;
    // 总的数据条数
    @ApiModelProperty(value = "总条数")
    private Long totalRecord;
    // 总页数
    @ApiModelProperty(value = "总页数")
    private Long totalPage;
    // 数据集合
    @ApiModelProperty(value = "数据集合")
    private List<T> dataList;

    public PageBean(Integer currentNo, Integer pageSize) {
        this.currentNo = currentNo;
        this.pageSize = pageSize;
    }

    /**
     * @param currentNo   当前页
     * @param pageSize    单页显示数据条数
     * @param totalRecord
     */
    public PageBean(Integer currentNo, Integer pageSize, Long totalRecord, List<T> dataList) {
        this.currentNo = currentNo;
        this.pageSize = pageSize;
        this.totalRecord = totalRecord;
        this.dataList = dataList;
        // 获取总页数
        if (totalRecord % pageSize == 0) {
            this.totalPage = totalRecord / pageSize;
        } else {
            this.totalPage = totalRecord / pageSize + 1;
        }
 
		/*this.startIndex = (currentNo - 1) * pageSize;
		this.start = 1L;
		this.end = 5L;
		if (totalPage <= 5)
		{
			this.end = this.totalPage;
		} else
		{
			this.start = currentNo - 2;
			this.end = currentNo + 2;
			if (start < 0)
			{
				start = 1L;
				end = 5L;
			}
			if (end > this.totalPage)
			{
				this.end = totalPage;
				this.start = end - 5;
			}
		}*/
    }
}